#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
map<LL,LL>map1;
LL sum[maxn];
char str[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    map1.clear();
    LL n,x;cin>>n>>x;
    for(LL i=0;i<n+10;i++) sum[i]=0;
    cin>>(str+1);
    for(LL i=1;i<=n;i++){
        sum[i]=sum[i-1];
        if(str[i]=='0') sum[i]++;
        if(str[i]=='1') sum[i]--;
    }
    for(LL i=1;i<=n;i++){
        map1[sum[i]]++;
    }
    if(sum[n]==0){
      if(!map1.count(x)){
        cout<<"0"<<"\n";
      }
      else{
        cout<<"-1"<<"\n";
      }
    }
    else if(sum[n]!=0){
        LL ans=0;
        if(x==0) ans++;
        for(auto j:map1){
            if(   (x-j.first)%abs(sum[n])==0 ){

                    if( (x-j.first)<0&&sum[n]>0) continue;
                    if( (x-j.first)>0&&sum[n]<0) continue;
                    ans+=j.second;
            }
        }
        cout<<ans<<"\n";
    }
  }
return 0;
}
